var vue = null;
$(function() {
    init_vue();
});

function init_vue() {
    vue = new Vue({
        el : "#myapp",
        data : {
            startRow : 0,
            endRow : 0,
            total : 0,
            firstPage : 0,
            lastPage : 0,
            pageNum : 1,
            pageSize : 13,
            list : null,
            navigatepageNums : null,
            data_cycle:'',
            nick_name:'',
            mobile_phone:'',
            type:0,
            source:0,
			remark:'',
            total_recharge:0,
            total_withdrawals:0
        },
        events : {},
        methods : {
            init : function() {
                close_layuiLayerLoad();
                this.initControl();
                this.getData();
            },
            initControl:function () {
                var t = this;
                $('#data_cycle').daterangepicker({
                    type: 2,
                    // drops: 'up',
                    // startDate: moment().subtract('year', 1),
                    startDate: d,
                    endDate: moment(),
                    autoApply:false,
                    autoUpdateInput:true,
                    showDropdowns : true,
                    ranges : {
                        '今日': [moment().startOf('day'), moment()],
                        '昨日': [moment().subtract('days', 1),  moment()],
                        '最近7日': [moment().subtract('days', 6), moment()],
                        '最近30日': [moment().subtract('days', 29), moment()]
                    },
                    opens : 'right', //日期选择框的弹出位置
                    separator : ' to ',
                    locale : {
                        separator:'/',
                        format : 'YYYY-MM-DD', //控件中from和to 显示的日期格式
                        applyLabel : '确定',
                        cancelLabel : '取消',
                        fromLabel : '起始时间',
                        toLabel : '结束时间',
                        customRangeLabel : '自定义',
                        daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
                        monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
                            '七月', '八月', '九月', '十月', '十一月', '十二月' ],
                        firstDay : 1
                    }
                }, function(start, end, label) {
                    //格式化日期显示框
                    t.data_cycle = start.format('YYYY-MM-DD') + '/' + end.format('YYYY-MM-DD');
                });
            },
            showPage : function(page) {
                // alert(page);
                this.pageNum = page;
                this.getData();
            },
            getData : function() {
                showLoad();
                var t = this;
                postMsg(root+"/rechargeWithdrawals/toQuery", {
                    page_num : t.pageNum,
                    page_size : t.pageSize,
                    data_cycle: t.data_cycle,
                    nick_name: t.nick_name,
                    audit_state: audit_state,
                    mobile_phone: t.mobile_phone,
                    type: t.type,
                    source: t.source,
					remark: t.remark
                }, function(i) {
                    t.list = null;
                    t.list = i.data.list;
                    t.startRow = i.data.startRow;
                    t.endRow = i.data.endRow;
                    t.total = i.data.total;
                    t.firstPage = i.data.firstPage;
                    t.lastPage = i.data.lastPage;
                    t.navigatepageNums = i.data.navigatepageNums;
                    t.total_recharge = i.total_recharge;
                    t.total_withdrawals = i.total_withdrawals;
                    hideLoad();
                });
            },
            query : function () {
                this.pageNum = 1;
                this.getData();
            },
            reset_query : function () {
                agent_id_select.val(null).trigger("change");
                this.data_cycle=d+'/'+moment().format('YYYY-MM-DD');
                this.nick_name='';
                this.mobile_phone='';
            },
            gotoInfoPage : function (id) {
                window.location.href = root + '#user/info/id/' + id;
            },
            audit: function (id, audit_state, type) {
                var t = this;
                if (audit_state == 1) {
                    if (type == 1) {
                        layer.confirm('请确认对方资金是否已入账', {
                            btn: ['已确认入账','在检查一下', '取消'] //按钮
                            ,closeBtn: 0
                        }, function(index){
                            layer.close(index);
                            t.subAudit(id, audit_state, 0);
                        });
                    } else {
                        layer.confirm('出金申请已通过后，是否进行第三方代付', {
                            btn: ['第三方代付','手动银行转帐', '取消'] //按钮
                            ,closeBtn: 0
                        }, function(index){
                            layer.close(index);
                            // aaa(id, state, obj, 1);
                            // layer.alert("功能暂不能用");
                            t.subAudit(id, audit_state, 1);
                        }, function(){
                            t.subAudit(id, audit_state, 0);
                            // aaa(id, state, obj, 0);
                        });
                    }
                } else {
                    layer.confirm('确定要拒绝该提现申请吗', {
                        btn: ['确定','取消'] //按钮
                        ,closeBtn: 0
                    }, function(index){
                        layer.close(index);
                        // aaa(id, state, obj, 1);
                        // layer.alert("功能暂不能用");
                        t.subAudit(id, audit_state, 0);
                    });
                }
            },
            subAudit: function (id, audit_state, auto) {
                postMsg(root+"/rechargeWithdrawals/subAuditRechargeOrWithdrawals", {
                    id : id,
                    audit_state : audit_state,
                    auto:auto
                }, function(i) {
                    if (i.code == 1) {
                        $.scojs_message('操作成功', $.scojs_message.TYPE_OK);
                    } else {
                        $.scojs_message('操作失败', $.scojs_message.TYPE_ERROR);
                    }
                });
            }
        }
    });
    vue.init();
}